package com.etc.controller;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(value = "cookieapi")
public class CookieController {

	/**
	 * 写cookie到本地
	 * 
	 * @param response
	 * @return
	 */
	@RequestMapping("setcookie")
	public String setCookie(HttpServletResponse response) {
		Cookie cookie = new Cookie("name", "springmvc");
		response.addCookie(cookie);
		return "cookie";
	}

	/**
	 * 读取本地的cookie
	 * @param name
	 * @return
	 */
	@RequestMapping("getcookie")
	public String getCookie(@CookieValue(value = "name") String name) {
		System.out.println("cookie :" + name);
		return "cookie";
	}
	
	@RequestMapping("getjsid")
	public String getjsid(@CookieValue(value = "JSESSIONID") String JSESSIONID) {
		System.out.println("JSESSIONID :" + JSESSIONID);
		return "cookie";
	}

}
